import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 停线登记信息 */
export interface LinestopRegistration {
  id: number // 类型id
  registrationDate: string | Dayjs // 日期
  workshopName: string // 车间名
  proposer: string // 提出人
  category: number // 停线类型
  question: string // 停线问题
  reason?: string // 停线原因
  startTime?: string | Dayjs // 开始时间
  endTime?: string | Dayjs // 结束时间
  duration?: number // 持续时间(分钟)
  responsibleDepartment: string // 责任部门
  responsiblePerson: string // 责任人
  numberOfAffected?: number // 影响人数
  submitIf: number // 是否提交
}

// 停线登记 API
export const LinestopRegistrationApi = {
  // 查询停线登记分页
  getLinestopRegistrationPage: async (params: any) => {
    return await request.get({ url: `/mold/linestop-registration/page`, params })
  },

  // 查询停线登记详情
  getLinestopRegistration: async (id: number) => {
    return await request.get({ url: `/mold/linestop-registration/get?id=` + id })
  },

  // 新增停线登记
  createLinestopRegistration: async (data: LinestopRegistration) => {
    return await request.post({ url: `/mold/linestop-registration/create`, data })
  },

  // 修改停线登记
  updateLinestopRegistration: async (data: LinestopRegistration) => {
    return await request.put({ url: `/mold/linestop-registration/update`, data })
  },

  // 删除停线登记
  deleteLinestopRegistration: async (id: number) => {
    return await request.delete({ url: `/mold/linestop-registration/delete?id=` + id })
  },

  /** 批量删除停线登记 */
  deleteLinestopRegistrationList: async (ids: number[]) => {
    return await request.delete({
      url: `/mold/linestop-registration/delete-list?ids=${ids.join(',')}`
    })
  },

  // 导出停线登记 Excel
  exportLinestopRegistration: async (params) => {
    return await request.download({ url: `/mold/linestop-registration/export-excel`, params })
  }
}
